package com.jk.smartelderlycare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.smartelderlycare.dao.SysSupplierMapper;
import com.jk.smartelderlycare.dto.SysSupplier;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.service.SysSupplierService;
import com.jk.smartelderlycare.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysSupplierServiceImpl
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/12/5 11:48
 */
@Service
public class SysSupplierServiceImpl implements SysSupplierService {
    @Autowired
    private SysSupplierMapper sysSupplierMapper;
    /**
     * @description: 后端分页
     * @param: [sysGoods]
     * @return: void
     * @author hhk
     * @date: 2024/12/5 10:40
     */
    @Override
    public PagedResponse<SysSupplier> findSysSupplierPaginationList(SysSupplier sysSupplier, Integer pageNum, Integer pageSize) {
        Page<SysSupplier> page = new Page<>(pageNum, pageSize);
        QueryWrapper<SysSupplier> queryWrapper = new QueryWrapper<>();
        if (null != sysSupplier.getSupplierName() && !"".equals(sysSupplier.getSupplierName())) {
            queryWrapper.like("supplier_name", sysSupplier.getSupplierName());
        }
        if (null != sysSupplier.getWarehouse() && !"".equals(sysSupplier.getWarehouse())) {
            queryWrapper.like("warehouse", sysSupplier.getWarehouse());
        }
        if (null != sysSupplier.getStartDate() && !"".equals(sysSupplier.getStartDate())) {
            queryWrapper.le("create_data", sysSupplier.getStartDate());
        }
        if (null != sysSupplier.getEndDate() && !"".equals(sysSupplier.getEndDate())) {
            queryWrapper.ge("create_data", sysSupplier.getEndDate());
        }
        Page<SysSupplier> sysSupplierList = sysSupplierMapper.selectPage(page, queryWrapper);
        return PaginationUtil.getPagedResponse(sysSupplierList.getRecords(), pageNum, pageSize, sysSupplierList.getTotal());

    }
    /**
     * @description: 导出
     * @param: []
     * @return: java.util.List<com.jk.smartelderlycare.dto.SysGoods>
     * @author hhk
     * @date: 2024/12/5 10:43
     */
    @Override
    public List<SysSupplier> findSysSupplierList() {
        return sysSupplierMapper.selectList(null);
    }
}
